/*
 * @Author: wangzhongjie
 * @Date: 2020-03-05 15:47:02
 * @LastEditors: wangzhongjie
 * @LastEditTime: 2020-03-05 16:49:02
 * @Description:读取图片列表
 * @Email: UvDream@163.com
 */

package other

import (
	"go-gin-api/app/util"
	"io/ioutil"

	"github.com/gin-gonic/gin"
)

type imageList struct {
	// FileName 名称
	FileName string `json:"file_name"`
	// Size 大小
	Size int64 `json:"size"`
}

// GetImagesService 读取images服务
func GetImagesService(c *gin.Context) *util.Response {
	return &util.Response{
		Code:    200,
		Message: "success",
		Data:    getFileList("./images"),
	}
}

// 读取文件
func getFileList(path string) []*imageList {
	imagesList := make([]*imageList, 0)
	fs, _ := ioutil.ReadDir(path)
	for _, file := range fs {
		if file.IsDir() {
			continue
		} else {
			obj := &imageList{}
			obj.FileName = file.Name()
			obj.Size = file.Size()
			imagesList = append(imagesList, obj)
		}
	}
	return imagesList
}
